package com.jblv.frame.common.enums;

/**
 * <p>异常枚举类</p>
 *
 * @author jblv
 * @version 1.0
 * @date 2019/6/15 0015
 * @since jdk1.8
 */
public enum ExceptionEnum {
    // 签名异常
    SIGN_ERROR(1001, "签名异常"),
    // 参数异常
    PARAM_ERROR(1002, "参数异常"),
    // 数据不存在
    DATA_NOT_FUND(1003, "数据不存在"),
    // 登录异常
    LOGIN_ERROR(1004, "登录异常"),
    // 权限异常
    PERMISSION_ERROR(1005, "权限异常"),
    // 服务异常
    SERVICE_ERROR(1006, "服务异常"),
    // 异常操作
    OPERATE_ERROR(1007, "异常操作"),
    // 异常请求
    REQUEST_ERROR(1008, "异常请求"),

    REQUEST_HEAD_ERROR(10403,"请求头部参数格式错误"),

    // 未知错误
    UNKNOW_ERROR(1009, "未知错误"),

    USER_USERNAME_EMPTY(10110,"登录名不能为空"),
    USER_PASSWORD_EMPTY(10111,"用户密码不能为空"),
    USER_PASSWORD_ERROR(10210,"用户密码错误"),

    USER_NOT_LOGIN_ERROR(10310,"访问未授权"),
    USER_TOKEN_EXPIRE(10311,"授权已过期"),

    DATA_UPDATE_FAILE(10410,"数据更新失败"),
    DATA_CREATE_FAILE(10411,"数据创建失败"),
    DATA_DELETE_FAILE(10412,"数据删除失败"),
    DATA_SELECT_FAILE(10413,"数据查询失败"),

    ;

    private int code;

    private String message;

    ExceptionEnum(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public static String getMessage(int code) {
        for (ExceptionEnum type : values()) {
            if (type.getCode() == code) {
                return type.getMessage();
            }
        }
        return null;
    }
}
